const videoSuffix = ["wmv", "asf", "asx", "rm", "rmvb", "mp4", "3gp", "mov", "m4v", "avi", "dat", "mkv", "flv", "vob"];
const imageSuffix = ["bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp", "avif", "apng"]
const zippedSuffix = ["rar", "tar", "gz", "jar", "war", "zip", "7z"];
const audioSuffix = ["mp3", "wav", "midi", "wma", "flac", "mpc", "ogg", "aiff", "voc"];
const linkSuffix = ["link", "url"];
const codeSuffix = ["java", "c", "cpp", "h", "hpp", "python", "kt", "js", "ts", "vue", "jsx", "css", "php", "asp", "aspx", "cs", "jsp", "xml"]

const specialSuffix = [
    'pdf', 'txt', 'apk', 'psd', 'ai', 'exe', 'html', 'iso', 'cloud'
]

//
// Exp.
//     import {typeOfFile} From "judgeFileType";
//     Just use like typeOfFile(fileName) === 'word'
//
// ousc Sep.27.2021 14:31:15

export const typeOfFile = function (fileName) {
    if(!fileName) return 'unknown';
    let fileNameSplited = fileName.split(".");
    const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
    if (specialSuffix.includes(suffix)) return suffix;
    if (suffix === 'docx' || suffix === 'doc') return 'word';
    if (suffix === 'xlsx' || suffix === 'xls') return 'excel';
    if (suffix === 'pptx' || suffix === 'ppt') return 'ppt';
    if (suffix === 'dwg') return 'cad';
    if (suffix === 'swf') return 'flash';
    if (suffix === 'msi') return 'exe';
    if (suffix === 'torrent') return 'bt';
    if (codeSuffix.includes(suffix)) return 'code';
    if (imageSuffix.includes(suffix)) return 'image';
    if (audioSuffix.includes(suffix)) return 'audio';
    if (videoSuffix.includes(suffix)) return 'video';
    if (zippedSuffix.includes(suffix)) return 'zip';
    if (linkSuffix.includes(suffix)) return 'link';
    return "other";
}


//
// Exp.
//     import {J} From "judgeFileType";
//     Just use like J.isPpt(fileName)
//
// ousc Sep.27.2021 14:31:15

export const J = {

    isPdf: (fileName) => {
        let fileNameSplited = fileName.split(".");
        const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
        return suffix === "pdf";
    },

    isImage: (fileName) => {
        let fileNameSplited = fileName.split(".");
        const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
        return imageSuffix.includes(suffix);
    },

    isAudio: (fileName) => {
        let fileNameSplited = fileName.split(".");
        const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
        return musicSuffix.includes(suffix);
    },

    isWord: (fileName) => {
        let fileNameSplited = fileName.split(".");
        const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
        return suffix === "docx";
    },

    isTxt: (fileName) => {
        let fileNameSplited = fileName.split(".");
        const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
        return suffix === "txt";
    },

    isPpt: (fileName) => {
        let fileNameSplited = fileName.split(".");
        const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
        return suffix === "pptx";
    },

    isExcel: (fileName) => {
        let fileNameSplited = fileName.split(".");
        const suffix = fileNameSplited[fileNameSplited.length - 1]?.toLocaleLowerCase();
        return suffix === "xlsx" || suffix === "xls";
    }
};
